package com.zhuss.core.processor;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.core.banner.CreateBannerBo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.core.db.dao.ext.BannerDao;
import com.zhuss.core.db.entity.Banner;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.WpsException;
import com.zhuss.util.JsonUtil;

/**
 * 创建banner processor
 * @Author: zhushanshuo
 * @Date: 2019/9/24 19:54
 */
@Component("bannerCreate")
public class BannerCreate extends AbstractProcessor<Object, CreateBannerBo> implements Processor<Object, CreateBannerBo> {

    @Autowired
    private BannerDao bannerDao;
    
    @Autowired
	@Qualifier("bannerRead")
	private BannerRead bannerRead;
    
    
    /**
     * 校验
     */
    @Override
    public void check(CreateBannerBo bo) throws WpsException {
    	
    	// bo.setArea(bannerRead.findMaxAreaIncr());
    }
    
    /**
     * 操作方法
     */
    @Override
    public Object process(CreateBannerBo param) {
    	Banner record = new Banner();
    	record.setType(param.getType());
    	record.setName(param.getName());
    	record.setContent(param.getContent());
    	record.setGo(param.getGo());
    	record.setPic(param.getPic());
    	record.setSort(param.getSort());
    	
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	bannerDao.create(record);
    	param.setTargetId(record.getBannerId());
        return null;
    }
    
    /**
     * 操作日志
     */
	@Override
	public Object log(CreateBannerBo param) throws WpsException {
		OpLog record = new OpLog();
    	record.setMoudle(MoudleEnum.基础模块.key());
    	record.setAction(LogActionEnum.banner创建.key());
    	record.setTargetId(param.getTargetId());
    	record.setTargetName(param.getName() + "");
    	record.setContent("参数: " + JsonUtil.toJson(param));
    	record.setReason(param.getExceptionReason());
    	
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	log(record);
    	return null;
	}
}
